import axios from 'axios'
import cookie from './cookie.js'
import qs from 'qs'
import router from '../src/router'


axios.defaults.timeout=10000;
axios.defaults.headers.common['userId'] =cookie.getCookie('userId') ;
axios.defaults.headers.common['ticket'] = cookie.getCookie('ticket');
axios.defaults.headers.common['account'] = cookie.getCookie('account');
axios.defaults.headers.common['platform'] = 'PC';
axios.defaults.headers.common['login_auth_token'] = cookie.getCookie('login_auth_token');
axios.defaults.headers.common['money_auth_token'] = cookie.getCookie('money_auth_token');


axios.interceptors.request.use(function(config){
	if(config.method == 'post'){
		config.data = qs.stringify(config.data);
	}
	return config;
});

axios.interceptors.response.use(function(data){
if(data.data.code == '002'){
		router.push('/login');
	}else{
		return data;
	}
});


export default axios
